package com.jt.controller;

import com.jt.pojo.User;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/axios")
@CrossOrigin    //专门解决跨域问题
public class AxiosController {

    @GetMapping("/findStr")
    public String findStr(){
        return "高兴嘞个开心";
    }

    @GetMapping("/getUserById")
    public String getUserById(Integer id){
        return "获取数据："+id;
    }

    @GetMapping("/findUser")
    public User findUser(User user){
        return user;
    }

    @GetMapping("/result/{id}/{name}/{age}")
    public User result(User user){
        return user;
    }

    /**
     * 编辑后端Controller
     * URL：/axios/saveUser
     * 参数：json 串
     *      {id: 1000, name: "tomcat喵", age: 8784
     *  返回值 ：User
     *  难点:
     *      1.将json串转化为java对象   @RequestBody
     *      2.将java对象转化为json串！ @ResponseBody
     */
    @PostMapping("/saveUser")
    public User saveUser(@RequestBody User user){
        return user;
    }
}
